// Created by 11372 on 2021/12/16 9:52
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

/**
 * 执行用时：428 ms, 在所有 C++ 提交中击败了81.71%的用户
 * 内存消耗：159.7 MB, 在所有 C++ 提交中击败了52.44%的用户
 */
class Solution {
public:
    int visiblePoints(vector<vector<int>>& points, int angle, vector<int>& location) {

        int cnt = 0;  // 重合的点数
        vector<double> ps;
        for (auto &p : points) {
            if (p == location) cnt++;
            else ps.push_back(atan2(p[1] - location[1], p[0] - location[0]));
        }
        sort(ps.begin(), ps.end());

        int n = ps.size();
        for (int i = 0; i < n; i++) ps.push_back(ps[i] + M_PI * 2);

        double dg = angle * M_PI / 180;
        int s = 0;
        for (int i = 0, j = 0; i < n; i++) {
            while (j + 1 < ps.size() && ps[j + 1] <= ps[i] + dg) j++;
            s = max(s, j - i + 1);
        }
        return cnt + s;
    }
};

int main() {

    vector<vector<int>> points = {
            {2, 1},
            {2, 2},
            {3, 3}
    };
    vector<int> location = {1, 1};
    cout << Solution().visiblePoints(points, 90, location) << endl;  // 3

    return 0;
}
